a11y: Allow setting the role post-construction
authorEmmanuele Bassi <ebassi@gnome.org>
Sun, 26 Jul 2020 19:27:39 +0000 (20:27 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Sun, 26 Jul 2020 20:27:03 +0000 (21:27 +0100)
Some widgets have different roles after they are constructed, so we need
to allow changing the role defined by the class. We should still avoid
setting a role after the GtkATContext has been created.

gtk/gtkaccessible.c
gtk/gtkwidget.c
testsuite/gtk/defaultvalue.c
testsuite/gtk/notify.c

index 2638abcd1cb9a059d2b127cf5bdab999d9036a3f..09227b86e179ae7616e0dd8a44637f502f41bcef 100644 (file)
@@ -62,7 +62,6 @@ gtk_accessible_default_init (GtkAccessibleInterface *iface)
                        GTK_TYPE_ACCESSIBLE_ROLE,
                        GTK_ACCESSIBLE_ROLE_NONE,
                        G_PARAM_READWRITE |
-                       G_PARAM_CONSTRUCT_ONLY |
                        G_PARAM_STATIC_STRINGS);
 
   g_object_interface_install_property (iface, pspec);
index b3e1c61e689e2d8c14e1fa0d8dde9292e2898751..f6da8f46db236e20fd41a7227f07bbe796a063a3 100644 (file)
@@ -1721,7 +1721,19 @@ gtk_widget_set_property (GObject         *object,
       gtk_widget_set_layout_manager (widget, g_value_dup_object (value));
       break;
     case PROP_ACCESSIBLE_ROLE:
-      priv->accessible_role = g_value_get_enum (value);
+      if (priv->at_context == NULL)
+        {
+          priv->accessible_role = g_value_get_enum (value);
+          g_object_notify_by_pspec (object, pspec);
+        }
+      else
+        {
+          char *role_str = g_enum_to_string (GTK_TYPE_ACCESSIBLE_ROLE, priv->accessible_role);
+          g_critical ("Widget of type ā€œ%sā€ already has an accessible role of type ā€œ%sā€",
+                      G_OBJECT_TYPE_NAME (object),
+                      role_str);
+          g_free (role_str);
+        }
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -8111,8 +8123,8 @@ gtk_widget_accessible_get_at_context (GtkAccessible *accessible)
       else
         role = class_priv->accessible_role;
 
-      priv->at_context = gtk_at_context_create (role, accessible);
       priv->accessible_role = role;
+      priv->at_context = gtk_at_context_create (role, accessible);
     }
 
   return priv->at_context;
index 3612ab84ba390cc6ab3739b67114d358a9daf066..d1bb4739bcc77d349a17314b5ed646216c9f965a 100644 (file)
@@ -144,6 +144,11 @@ test_type (gconstpointer data)
       if ((pspec->flags & G_PARAM_READABLE) == 0)
        continue;
 
+      /* This is set via class_init, and we have a11y tests to verify it */
+      if (g_type_is_a (type, GTK_TYPE_ACCESSIBLE) &&
+          strcmp (pspec->name, "accessible-role") == 0)
+        continue;
+
       /* This is set via construct property */
       if (g_type_is_a (type, GTK_TYPE_BUILDER) &&
           strcmp (pspec->name, "scope") == 0)
@@ -387,7 +392,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
        continue;
 
       if (g_type_is_a (type, GTK_TYPE_WIDGET) &&
-         (strcmp (pspec->name, "name") == 0 ||
+          (strcmp (pspec->name, "name") == 0 ||
           strcmp (pspec->name, "display") == 0 ||
           strcmp (pspec->name, "style") == 0))
        continue;
index 58527375cf64480bf701e3cdba465349892d60cf..5dd4499577c753f6ee31266eaa7862b2e4019cf9 100644 (file)
@@ -522,6 +522,10 @@ test_type (gconstpointer data)
            g_str_equal (pspec->name, "vexpand")))
         continue;
 
+      if (g_type_is_a (type, GTK_TYPE_ACCESSIBLE) &&
+          g_str_equal (pspec->name, "accessible-role"))
+        continue;
+
       if (pspec->owner_type == GTK_TYPE_ENTRY &&
           g_str_equal (pspec->name, "im-module"))
         continue;